package com.gurun.codes.base;

import android.arch.lifecycle.Lifecycle;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;

import com.gurun.codes.App;
import com.trello.lifecycle2.android.lifecycle.AndroidLifecycle;
import com.trello.rxlifecycle2.LifecycleProvider;
import com.trello.rxlifecycle2.LifecycleTransformer;

public abstract class BaseAppCompatActivity extends AppCompatActivity {
    protected Context mContext;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        App.getInstance().addActivity(this);
        mContext = this;
    }

    private final LifecycleProvider<Lifecycle.Event> provider
            = AndroidLifecycle.createLifecycleProvider(this);

    public <T> LifecycleTransformer<T> bindToLifecycleDestroy() {
        return provider.bindUntilEvent(Lifecycle.Event.ON_DESTROY);
    }

    public <T> LifecycleTransformer<T> bindToLifecycle() {
        return provider.bindToLifecycle();
    }

    public <T> LifecycleTransformer<T> bindToLifecycleEvent(Lifecycle.Event event) {
        return provider.bindUntilEvent(event);
    }

    public LifecycleProvider<Lifecycle.Event> getProvider() {
        return provider;
    }

    protected abstract void initView();
    protected abstract void initDatas();
    protected abstract void initEvent();

}
